﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Caliburn.Micro.BikeWizard.Services;
using Caliburn.Micro.BikeWizard.Tests.Utils;
using Caliburn.Micro.BikeWizard.Utils;

namespace Caliburn.Micro.BikeWizard.Tests.BaseClasses
{
    public class TestBase : SilverlightTest
    {
        #region Protected Properties (Services)
        protected IBikeOptionService bikeOptionService { get { return IoC.Get<IBikeOptionService>(); } }
        #endregion

        #region Protected Methods (Others)
        protected IResult SetTestComplete()
        {
            return new ActionResult(
                (actionResult) =>
                {
                    EnqueueTestComplete();
                    actionResult.SetComplete(null);
                });
        }

        protected TView CreateViewForViewModel<TView>(object viewModel) where TView : class
        {
            var view = ViewLocator.LocateForModel(viewModel, null, null);
            ViewModelBinder.Bind(viewModel, view, null);
            Assert.IsNotNull(view as TView);

            if (viewModel is Screen)
                Assert.AreEqual((viewModel as Screen).GetView(null), view);

            return view as TView;
        }

        protected T GetUiElement<T>(string name) where T : UIElement
        {
            return (T)(this.TestPanel.Children[0] as FrameworkElement).FindName(name);
        }
        #endregion
    }
}
